package cn.wolfcode.trip.admin.Controller;


import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.query.StrategyCommentQuery;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 攻略目录资源控制器
 */
@Controller
@RequestMapping("/strategyComment")
public class StrategyCommentController {

    @Autowired
    private IStrategyCommentService commentService;

    @Autowired
    private IStrategyService strategyService;

    /**
     * 查询出所有的点评
     * 含高级查询/分页
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String query(@ModelAttribute("qo") StrategyCommentQuery qo, Model model){
        qo.setOrderBy("sc.createTime desc");
        model.addAttribute("strategys",strategyService.listAll());
        PageInfo<StrategyComment> pageInfo= commentService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/strategyComment/list";
    }

    /**
     * 修改点评状态
     * @param strategyComment
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public JSONResult update(StrategyComment strategyComment){
        JSONResult jsonResult =new JSONResult();
        try {
            commentService.update(strategyComment);
        } catch (Exception e) {
            jsonResult.mark("操作失败,请稍后再试");
            e.printStackTrace();
        }
        return new JSONResult();
    }
}
